#include<stdio.h>
int fac(int y)
{
	return (((y%4==0)&&(y%100 !=0))||(y%400==0));
}
//



int main()
{
	int y;
	int m;
	int d;
	int arr[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
	while(scanf("%d %d",&y,&m))
	{
		int d=arr[m];
		if((fac(y)==1)&&(y==2))
		{
			d++;
		}
		printf("%d",d);
	}
}
